package nayasis.common.device.input;

import java.util.Observable;

import nayasis.common.log.NLogger;

public class GamePadEventMonitorThread extends Observable implements Runnable {

	private GamePadEvent gamePad = null;
	
	public GamePadEventMonitorThread( GamePadEvent gamePad ) {
		this.gamePad = gamePad;
	}
	
	@Override
	public void run() {

		try {

			while( ! Thread.currentThread().isInterrupted() ) {
				
				if( ! gamePad.poll() ) {
					Thread.sleep( 1000 );
					continue;
				}
				
				if( ! gamePad.isAnyPressed() ) continue;
				
				setChanged();
				
				notifyObservers( gamePad );
				
				Thread.sleep( 100 );
				
			}
			
		} catch( InterruptedException e ) {
			NLogger.err.println( e );
		}
		
		
	}
	
}
